<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8"></meta>
		<title>支付</title>
		<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" >  </script>				
	</head>
<body>
</body>
<script  th:inline="javascript" type="text/javascript">
/*<![CDATA[*/
         
           
           
    alert("AA");
	var returnurl =[[${returnurl}]];
	var itemid =[[${itemid}]];
	var userid =[[${userid}]];
	var packageParams = [[${packageParams}]];
	
	alert(returnurl);
	
	$(function(){
		returnurl = returnurl.replace(/jing/g, '#');
		returnurl = returnurl.replace(/wenhao/g, '?');
    	returnurl = returnurl.replace(/bingqie/g, '&');
		wxInit();
		if(packageParams.success){
			onPayReady();
		}else{
			alert(packageParams.message);
		}
	});
	
	function wxInit(){
		 wx.config({
		     debug: 	false,
		     appId:     packageParams.appId,
		     timestamp: packageParams.timeStamp,
		     nonceStr:  packageParams.nonceStr,
		     signature: packageParams.signature,
		     jsApiList: [
		       'chooseWXPay'
		     ]
		 });		
	}
	
	function onPayReady(){
		wx.ready(function() {
	        wx.chooseWXPay({  
	            appId: packageParams.appId,  
	            timestamp: packageParams.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符  
	            nonceStr: packageParams.nonceStr, // 支付签名随机串，不长于 32 位  
	            package: packageParams.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）  
	            signType: packageParams.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'  
	            paySign: packageParams.paySign, // 支付签名  
	            success: function(res) {  
	                // 支付成功后的回调函数  
	                if (res.errMsg == "chooseWXPay:ok") {  
	                	if(returnurl.indexOf("?") > 0){
	                		returnurl+="&ispaysuccess=1";
	                	}else{
	                		returnurl+="?ispaysuccess=1";
	                	}
	       				window.location.href = returnurl;
	                } else {  
	                	alert("支付失败！");
	                	if(returnurl.indexOf("?") > 0){
	                		returnurl+="&ispaysuccess=0";
	                	}else{
	                		returnurl+="?ispaysuccess=0";
	                	}
	       				window.location.href = returnurl;
	                }
	            },cancel: function(res) {  
                	if(returnurl.indexOf("?") > 0){
                		returnurl+="&ispaysuccess=0";
                	}else{
                		returnurl+="?ispaysuccess=0";
                	}
       				window.location.href = returnurl;
	            }  
	        });
	    });
   	}	
/*]]>*/
</script>
</html>



